package j.framework.tags.easyui;

import j.framework.tags.form.FormTagWriter;
import j.util.StringUtils;

import javax.servlet.jsp.JspException;
import java.util.Map;

/**
 * easyui 之combotree
 * User: jason
 * Date: 2015/1/16 15:45
 */
public class CombotreeTag extends BaseEasyuiLoadRemoteDataFormControl {
    private String selectedValue;
    private String onLoadSuccess;
    private String onBeforeSelect;
    private String onSelect;
    @Override
    public void writeFormTagBegin(FormTagWriter writer) throws JspException {
        writer.beginTag("select");
    }

    @Override
    public void writeFormTagProperties(FormTagWriter writer) throws JspException {

    }

    @Override
    public void writeEasyuiDataOptions(Map<String, Object> dataOptions)throws JspException{
        super.writeEasyuiDataOptions(dataOptions);
        if(StringUtils.isNotEmpty(selectedValue)){
            dataOptions.put("value",selectedValue);
        }else{
            Object value = getFormDataValue();
            if(value!=null){
                dataOptions.put("value",value.toString());
            }
        }
        if(StringUtils.isNotEmpty(onLoadSuccess)){
            dataOptions.put("onLoadSuccess",onLoadSuccess);
        }
        if(StringUtils.isNotEmpty(onBeforeSelect)){
            dataOptions.put("onBeforeSelect",onBeforeSelect);
        }
        if(StringUtils.isNotEmpty(onSelect)){
            dataOptions.put("onSelect",onSelect);
        }
    }

    @Override
    public void endBeginTag(FormTagWriter writer) throws JspException {
        writer.writeSomething(">");
        writer.closeTag("select");
    }

    @Override
    public String getEasyuiClassName() {
        return "easyui-combotree";
    }

    @Override
    protected String getControlWidth() {
        return "100%";
    }

    public void setSelectedValue(String selectedValue) {
        this.selectedValue = selectedValue;
    }

    public void setOnLoadSuccess(String onLoadSuccess) {
        this.onLoadSuccess = onLoadSuccess;
    }

    public void setOnBeforeSelect(String onBeforeSelect) {
        this.onBeforeSelect = onBeforeSelect;
    }

    public void setOnSelect(String onSelect) {
        this.onSelect = onSelect;
    }
}
